/**
 * Created by lihao on 15/8/20.
 */
define(["jquery", "metisMenu", "select2"], function ($) {

  $('#side-menu').metisMenu();


  var ajaxbg = $("#hxz-background,#hxz-progressBar");
  ajaxbg.hide();

  $(document).ajaxStart(function () {
    ajaxbg.show();
  }).ajaxStop(function () {
    ajaxbg.hide();
  });

  $(window).bind("load resize", function () {
    topOffset = 50;
    width = (this.window.innerWidth > 0) ? this.window.innerWidth : this.screen.width;
    if (width < 768) {
      $('div.navbar-collapse').addClass('collapse');
      topOffset = 100; // 2-row-menu
    } else {
      $('div.navbar-collapse').removeClass('collapse');
    }

    height = ((this.window.innerHeight > 0) ? this.window.innerHeight : this.screen.height) - 1;
    height = height - topOffset;
    if (height < 1) height = 1;
    if (height > topOffset) {
      $("#page-wrapper").css("min-height", (height) + "px");
    }
  });

  var url = window.location;
  var element = $('ul.nav a').filter(function () {
    return this.href == url || url.href.indexOf(this.href) == 0;
  }).addClass('active').parent().parent().addClass('in').parent();
  if (element.is('li')) {
    element.addClass('active');
  }

  //$.fn.select2.locales['zh-CN'] = {
  //  formatNoMatches: function () {
  //    return "没有找到匹配项";
  //  },
  //  formatInputTooShort: function (input, min) {
  //    var n = min - input.length;
  //    return "请再输入" + n + "个字符";
  //  },
  //  formatInputTooLong: function (input, max) {
  //    var n = input.length - max;
  //    return "请删掉" + n + "个字符";
  //  },
  //  formatSelectionTooBig: function (limit) {
  //    return "你只能选择最多" + limit + "项";
  //  },
  //  formatLoadMore: function (pageNumber) {
  //    return "加载结果中…";
  //  },
  //  formatSearching: function () {
  //    return "搜索中…";
  //  }
  //};

  //$.extend($.fn.select2.defaults, $.fn.select2.locales['zh-CN']);

  return {
    progressBar: ajaxbg
  }
});